package com.xiaoma.verbal.utils;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import com.baidu.yun.push.exception.PushClientException;
import com.baidu.yun.push.exception.PushServerException;
import com.xiaoma.tpo.domain.UserMessage;
import com.xiaoma.tpo.utils.baidupush.AndroidPushMsg;
import com.xiaoma.tpo.utils.baidupush.BDPush;
import com.xiaoma.tpo.utils.baidupush.IOSPushMsg;

public class BaiduPush{

	
    /**
     * 安卓单播
     * 
     * @param userId
     * @param channelId
     * @param userMessage
     */
	public static void sendAndroidUnicastNotification(String userId, Long channelId, UserMessage userMessage) {
	    AndroidPushMsg androidMsg = new AndroidPushMsg();
        androidMsg.setTitle("托福21天");
        androidMsg.setDescription(userMessage.getMessage());
        JSONObject custom = new JSONObject();
        custom.put("flag",3);
        androidMsg.setCustomContent(custom);
	    try {
            BDPush.androidPush2Single(channelId.toString(), androidMsg);
        } catch (PushClientException | PushServerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
	}
	
	/**
     * ios单播
     * 
     * @param userId
     * @param channelId
     * @param userMessage
     */
	public static void sendIosNotification(String userId, Long channelId, UserMessage userMessage) {
	    IOSPushMsg msg = new IOSPushMsg();
        msg.setTitle(userMessage.getMessage());
        Map<String, Object> content = new HashMap<String, Object>();
        content.put("flag", 3);
        msg.setContent(content);
	    try {
            BDPush.iosPush2Single(channelId.toString(), msg);
        } catch (PushClientException | PushServerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
	}

}
